<?php

@include_once('./database.php');



$oldphonenumber = $_POST['oldphonenumber'];
$oldpassword = $_POST['oldpassword'];
$newpassword = $_POST['newpassword'];





$obj = [] ;

if($oldpassword && $newpassword && $oldphonenumber){

    $sql = "select * from user where user_phonenumber = $oldphonenumber and user_password = $oldpassword" ;
    $sql2 = "update user set  user_password = $newpassword where user_phonenumber = $oldphonenumber and user_password = $oldpassword ";
    // $sql = "update user set password = '$password2' where username= '$username' and password = '$password'";
    
    // // 运行sql语句   mysqli_query()
    $res = mysqli_query($connect, $sql);
    // 把表格转成数组   mysqli_fetch_array()
    $arr = mysqli_fetch_array($res) ;

    

    if($arr) {
        // 匹配密码
        if($arr['user_password'] === $oldpassword) {
            $res = mysqli_query($connect , $sql2) ;
            $obj['status'] = true ;
            $obj['msg'] = '修改成功';

        } else {
           $obj['status'] = false ;
           $obj['msg'] = '手机号或密码错误';
           $obj['a'] = $oldphonenumber;
           $obj['b'] = $oldpassword;
           $obj['c'] = $newpassword ;
        }
    } else {
        $obj['status'] = false ;
        $obj['msg'] = '手机号或密码错误';
        $obj['a'] = '888';
    }


}else{
    $obj['status'] = false ;
    $obj['msg'] = '前端数据有误';
}

echo (json_encode($obj, JSON_UNESCAPED_UNICODE));
